package com.softer.wxzj.controller;


import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.ResourceTree;
import com.softer.wxzj.entity.SysRole;
import com.softer.wxzj.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * RoleController class
 *
 * @author zcz
 * @date 2019/4/10
 */
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleController {
    @Autowired
    RoleService roleService;

    @RequestMapping("/add")
    @LogRecord(description = "新增角色", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.INSERT)
    public CommonResult add(SysRole role) {
        return roleService.insert(role);
    }

    @RequestMapping("/update")
    @LogRecord(description = "修改角色", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.UPDATE)
    public CommonResult update(SysRole role) {
        return roleService.update(role);
    }

    @RequestMapping("/delete")
    @LogRecord(description = "删除角色", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return roleService.delete(id);
    }

    @RequestMapping("/getList")
    @LogRecord(description = "查询角色列表", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.SELECT)
    public PageInfo<SysRole> getList(Page page, SysRole role) {
        return roleService.getList(page, role);
    }

    @RequestMapping("/getListByType")
    @LogRecord(description = "查询角色列表填充下拉框", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.SELECT)
    public List<SysRole> getListByType(@RequestParam("type") String type) {
        return roleService.getListByType(type);
    }

    @RequestMapping("/getInfo")
    @LogRecord(description = "查询角色详情", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.SELECT)
    public SysRole getInfo(String id) {
        return roleService.getInfo(id);
    }

    @LogRecord(description = "查询角色树", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.SELECT)
    @RequestMapping("/getResourceTree")
    public List<ResourceTree> getResourceTree(String type) {
        return roleService.getResourceTree(type);
    }

    @RequestMapping("/fuzzySearch")
    @LogRecord(description = "模糊查询查询角色", operationUnit = LogOperationUnit.ROLE, operationType = LogOperationType.SELECT)
    public PageInfo<SysRole> fuzzySearch(Page page, String fuzzy) {
        return roleService.fuzzySearch(page, fuzzy);
    }
}
